package com.example.springboot.controller;

import com.example.springboot.base.Result;
import com.example.springboot.service.FileInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 赵久燚
 * @since 2022-07-11 19:45:42
 */
@RestController
@Api(tags = "文件")
@RequestMapping("/file")
public class FileInfoController {

    @Autowired
    private FileInfoService fileInfoService;

    @PostMapping("/uploadFile")
    @ApiOperation("上传文件")
    public Result uploadFile(
            @RequestPart("file") MultipartFile file,
            @RequestParam("folderId") String folderId
    ) throws IOException {
        return fileInfoService.uploadFile(file,folderId);
    }

    @PostMapping("deleteFile")
    @ApiOperation("删除文件")
    public Result deleteFile(
            @RequestParam("fileId") String fileId
    ){
        return fileInfoService.deleteFile(fileId);
    }

    @RequestMapping("downLoadFile")
    @ApiOperation("下载文件")
    public void downLoadFile(
            @RequestParam("fileId") String fileId,
            HttpServletResponse response
    ){
        fileInfoService.downLoadFile(fileId,response);
    }

}

